package com.xbts.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnVirtuallyUserBuyLog;
import com.xbts.system.service.ICnVirtuallyUserBuyLogService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 用户购买记录（虚拟）Controller
 * @author xbts
 * @date 2023-11-30
 */
@Api("用户购买记录（虚拟）")
@RestController
@RequestMapping("/system/virtually/log")
public class CnVirtuallyUserBuyLogController extends BaseController {

    @Autowired
    private ICnVirtuallyUserBuyLogService cnVirtuallyUserBuyLogService;

    /**
     * 查询用户购买记录（虚拟）列表
     */
    @ApiOperation("查询用户购买记录（虚拟）列表")
    @PreAuthorize("@ss.hasPermi('system:virtuallyLog:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnVirtuallyUserBuyLog cnVirtuallyUserBuyLog) {
        startPage(cnVirtuallyUserBuyLog);
        List<CnVirtuallyUserBuyLog> list = cnVirtuallyUserBuyLogService.selectCnVirtuallyUserBuyLogList(cnVirtuallyUserBuyLog);
        return getDataTable(list);
    }
    /**
     * 查询用户购买记录（虚拟）列表
     */
    @ApiOperation("查询用户购买记录（虚拟）列表")
    @PreAuthorize("@ss.hasPermi('system:virtuallyLog:list')")
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody CnVirtuallyUserBuyLog cnVirtuallyUserBuyLog) {
        return success(cnVirtuallyUserBuyLogService.statistics(cnVirtuallyUserBuyLog));
    }

    /**
     * 导出用户购买记录（虚拟）列表
     */
    @ApiOperation("导出用户购买记录（虚拟）列表")
    @PreAuthorize("@ss.hasPermi('system:virtuallyLog:export')")
    @Log(title = "用户购买记录（虚拟）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnVirtuallyUserBuyLog cnVirtuallyUserBuyLog) {
        List<CnVirtuallyUserBuyLog> list = cnVirtuallyUserBuyLogService.selectCnVirtuallyUserBuyLogList(cnVirtuallyUserBuyLog);
        ExcelUtil<CnVirtuallyUserBuyLog> util = new ExcelUtil<CnVirtuallyUserBuyLog>(CnVirtuallyUserBuyLog.class);
        util.exportExcel(response, list, "用户购买记录（虚拟）数据");
    }

    /**
     * 获取用户购买记录（虚拟）详细信息
     */
    @ApiOperation("获取用户购买记录（虚拟）详细信息")
    @ApiImplicitParam(name = "userId", value = "用户购买记录（虚拟）ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:virtuallyLog:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId) {
        return success(cnVirtuallyUserBuyLogService.selectCnVirtuallyUserBuyLogByUserId(userId));
    }

    /**
     * 新增用户购买记录（虚拟）
     */
    @ApiOperation("新增用户购买记录（虚拟）")
    @PreAuthorize("@ss.hasPermi('system:virtuallyLog:add')")
    @Log(title = "用户购买记录（虚拟）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnVirtuallyUserBuyLog cnVirtuallyUserBuyLog) {
        return toAjax(cnVirtuallyUserBuyLogService.insertCnVirtuallyUserBuyLog(cnVirtuallyUserBuyLog));
    }
    /**
     * 虚拟用户列表（添加时使用）
     */
    @ApiOperation("虚拟用户列表（添加时使用）")
    @GetMapping("/virtuallyUserList")
    public AjaxResult virtuallyUserList() {
        return success(cnVirtuallyUserBuyLogService.virtuallyUserList());
    }

    /**
     * 产品类型名称列表
     */
    @ApiOperation("产品类型列表")
    @GetMapping("/productTypeNameList")
    public AjaxResult productTypeNameList() {
        return success(cnVirtuallyUserBuyLogService.productTypeNameList());
    }

    /**
     * 产品名称列表
     */
    @ApiOperation("产品名称列表")
    @GetMapping("/productNameList/{type}/{id}")
    public AjaxResult productNameList(@PathVariable("type") String type, @PathVariable("id") String id) {
        return success(cnVirtuallyUserBuyLogService.productNameList(type, id));
    }

    /**
     * 修改用户购买记录（虚拟）
     */
    @ApiOperation("修改用户购买记录（虚拟）")
    @PreAuthorize("@ss.hasPermi('system:virtuallyLog:edit')")
    @Log(title = "用户购买记录（虚拟）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnVirtuallyUserBuyLog cnVirtuallyUserBuyLog) {
        return toAjax(cnVirtuallyUserBuyLogService.updateCnVirtuallyUserBuyLog(cnVirtuallyUserBuyLog));
    }

    /**
     * 删除用户购买记录（虚拟）
     */
    @ApiOperation("删除用户购买记录（虚拟）")
    @ApiImplicitParam(name = "userIds", value = "用户购买记录（虚拟）ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:virtuallyLog:remove')")
    @Log(title = "用户购买记录（虚拟）", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> id) {
        return toAjax(cnVirtuallyUserBuyLogService.deleteCnVirtuallyUserBuyLogByIds(id));
    }
}
